package com.micro.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.micro.entity.TrainTicketOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TrainTicketOrderRepository extends BaseMapper<TrainTicketOrder> {
    
    // 根据用户ID查询订单列表（按订单ID降序）
    @Select("SELECT 订单ID as orderId, 用户ID as userId, 列车ID as trainId, 出发站ID as departureStationId, 到达站ID as arrivalStationId, 车厢ID as carriageId, 座位ID as seatId, 座位类型 as seatType, 乘客ID as passengerId, 出发时间 as departureTime, 到达时间 as arrivalTime, 乘客姓名 as passengerName, 乘客身份证 as passengerIdCard, 票价 as price, 车票状态 as ticketStatus, 车次日期 as trainData, 支付时间 as paymentTime FROM 火车票订单 WHERE 用户ID = #{userId} ORDER BY 订单ID DESC")
    List<TrainTicketOrder> findByUserIdOrderByOrderIdDesc(@Param("userId") Long userId);
    
    // 根据用户ID查询订单列表
    @Select("SELECT * FROM 火车票订单 WHERE 用户ID = #{userId}")
    List<TrainTicketOrder> findByUserId(@Param("userId") Long userId);
    
    // 根据车票状态查询订单
    @Select("SELECT * FROM 火车票订单 WHERE 车票状态 = #{ticketStatus}")
    List<TrainTicketOrder> findByTicketStatus(@Param("ticketStatus") Byte ticketStatus);
    
    // 根据列车ID查询订单
    @Select("SELECT * FROM 火车票订单 WHERE 列车ID = #{trainId}")
    List<TrainTicketOrder> findByTrainId(@Param("trainId") Long trainId);
    
    // 根据列车ID和日期查询订单
    @Select("SELECT * FROM 火车票订单 WHERE 列车ID = #{trainId} AND 车次日期 = #{trainData}")
    List<TrainTicketOrder> findByTrainIdAndTrainData(@Param("trainId") Long trainId, @Param("trainData") String trainData);
}
